// 1.正则方法
const str1 = "asdfasdfwerwergfgfjcvbcretyuiupirty";
const str2 = "aabbccddee";
const str3 = "aabbcccddeee";
const statictis = (str) => {
  const sortStr = str.split("").sort().join("");
  console.log(sortStr); // aabccddeeeffffggiijprrrrssttuuvwwyy
  const reg = /(\w)\1+/g;
  let num = 0;
  let letter = "";
  sortStr.replace(reg, (x1, x2, x3, x4) => {
    console.log(x1, x2, x3, x4);
    if (x1.length > num) {
      num = x1.length;
      letter = x2;
    }
  });
  return {
    num,
    letter,
  };
};
// console.log(statictis(str1)); // { num: 4, letter: 'f' }
// console.log(statictis(str2)); // { num: 2, letter: 'a' }

// 2.
const getMost = (str) => {
  let maxNum = 0;
  let letters = [];
  while (str) {
    let letter = str.charAt(0);
    let arr = str.split(letter);
    let letterLength = str.length - arr.join("").length;
    str = arr.join("");
    if (letterLength > maxNum) {
      maxNum = letterLength;
      letters = [letter];
    } else if (letterLength === maxNum) {
      letters.push(letter);
    }
  }
  return {
    maxNum,
    letters,
  };
};
console.log(getMost(str2)); // { maxNum: 2, letters: [ 'a', 'b', 'c', 'd', 'e' ] }
console.log(getMost(str3)); // { maxNum: 3, letters: [ 'c', 'e' ] }
